import React from 'react'
import { BrowserRouter as Router, Route, Switch,Redirect } from 'react-router-dom'
import { connect } from 'react-redux'
import Main from './layout/main'
import Login from './layout/login'

const mapState = (state)=>{
    return {
        loginState:state.getIn(['user','loginState'])
    }
}
const App = ( { loginState }) => {
    return (
        <Router>
            <Switch>
            {/* <Route path="/login" component = { Login } /> */}
            {
                loginState ?
                <Redirect path="/login" to="/" /> :
                <Route path="/login" component = { Login } />
            }

            {/* <Route path="/" component = { Main } /> */}

            {
                // 前端验证用户的登录状态
                loginState ? 
                <Route path='/' component={Main} /> :
                <Redirect to='/login'/>
            } 
            </Switch>
        </Router>
    
    )
}



export default connect(mapState)(App)

